﻿using STT.Business;
using STT.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using STT.Layer.Connection;
using Microsoft.Reporting.WebForms;
using System.Data;
namespace STT.Admin.UserControls
{
    public partial class ucTimKiemHocVien : System.Web.UI.UserControl
    {
        ToolBox tb = new ToolBox();
        protected void Page_Load(object sender, EventArgs e)
        {
                Methods.ChucVu(ref ddChucVu);
                Methods.ChuyenMon(ref ddChuyenMon);
                Methods.DonViHocVien(ref ddDonVi);
                Methods.NgoaiNgu(ref ddTrinhDoNgoaiNgu);
                //Methods.MonHoc(ref ddMonHoc);
                Methods.Lop(ref ddLopHoc);
                tb.GetDataTableByNguoiTao("TbLop_SelectAll", Session["TenDN"].ToString());
                Methods.HocVan(ref ddHocVan);
        }

        protected void lbXuatDuLieu_Click(object sender, EventArgs e)
        {

        }

        protected void btTimKiem_Click(object sender, EventArgs e)
        {
            LoadDuLieu();
        }

        void LoadDuLieu()
        {
            DataTable dt = BTbHocVien.SelectStudentsBySearch(new ETbHocVien
            {
                MaHV = txtMaHocVien.Text != "" ? txtMaHocVien.Text : "",
                TenHV = txtTenHocVien.Text,
                MaDonVi = int.Parse(ddDonVi.SelectedValue.ToString()),
                ChucVu = int.Parse(ddChucVu.SelectedValue),
                TrinhDo = int.Parse(ddChuyenMon.SelectedValue),
                TDVanHoa = int.Parse(ddHocVan.Text.Trim()),
                DiaChi = txtDiaChi.Text,
                QueQuan = txtQueQuan.Text,
            }, txtTuoi.Text == "" ? -1 : int.Parse(txtTuoi.Text),
            txtSoKhoaHoc.Text != "" ? int.Parse(txtSoKhoaHoc.Text) : -1,
            int.Parse(ddTrinhDoNgoaiNgu.SelectedValue.ToString()),
            int.Parse(ddLopHoc.SelectedValue.ToString()),Session["TenDN"].ToString()
            );
            rpvHocVien.Visible = true;
            rpvHocVien.LocalReport.ReportPath = "RDLC\\TKEHocVien.rdlc";
            rpvHocVien.LocalReport.DataSources.Clear();
            rpvHocVien.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
        }

   

        protected void gvHocVien_DataBound(object sender, EventArgs e)
        {
            GridView gv1 = (GridView)sender;
            gv1.ShowFooter = true;

            if (gv1.Rows.Count > 0)
            {
                for (int i = gv1.Columns.Count - 1; i >= 1; i += -1)
                {
                    gv1.FooterRow.Cells.RemoveAt(i);
                }

                gv1.FooterRow.Cells[0].ColumnSpan = gv1.Columns.Count;

                gv1.FooterRow.Cells[0].HorizontalAlign = HorizontalAlign.Center;

                gv1.FooterRow.Cells[0].Text = "Tổng số kết quả tìm thấy: " + gv1.Rows.Count.ToString();
                gv1.FooterRow.Cells[0].Font.Bold = true;
            }
        }        
    }
}